import { createApp } from 'vue'
import App from './App.vue'

import ElementPlus from 'element-plus';
import 'element-plus/lib/theme-chalk/index.css';

// import "font-awesome/css/font-awesome.min.css"

// import Unicon from 'vue-unicons'
// import {uniGithub, uniGoogle, uniEnvelopeAlt, uniFile, uniFileAlt, uniShare,uniCommentsAlt, uniSearch,
//     uniTagAlt, uniCommentAltLines, uniBooks, uniCopy, uniCommentEdit, uniPostcard } from 'vue-unicons/dist/icons'

// Unicon.add([uniGithub, uniGoogle, uniEnvelopeAlt, uniFileAlt, uniShare,uniCommentsAlt, uniSearch,
//     uniFile, uniTagAlt, uniCommentAltLines, uniBooks, uniCopy, uniCommentEdit, uniPostcard])

import router from './router'

import VMdEditor from '@kangc/v-md-editor/lib/codemirror-editor';
import '@kangc/v-md-editor/lib/style/codemirror-editor.css';
import githubTheme from '@kangc/v-md-editor/lib/theme/github.js';
import '@kangc/v-md-editor/lib/theme/style/github.css';

// highlightjs
import hljs from 'highlight.js';

// codemirror 编辑器的相关资源
import Codemirror from 'codemirror';
// mode
import 'codemirror/mode/markdown/markdown';
import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/css/css';
import 'codemirror/mode/htmlmixed/htmlmixed';
import 'codemirror/mode/vue/vue';
// edit
import 'codemirror/addon/edit/closebrackets';
import 'codemirror/addon/edit/closetag';
import 'codemirror/addon/edit/matchbrackets';
// placeholder
import 'codemirror/addon/display/placeholder';
// active-line
import 'codemirror/addon/selection/active-line';
// scrollbar
import 'codemirror/addon/scroll/simplescrollbars';
import 'codemirror/addon/scroll/simplescrollbars.css';
// style
import 'codemirror/lib/codemirror.css';

VMdEditor.Codemirror = Codemirror;

VMdEditor.use(githubTheme, {
  Hljs: hljs,
});

import VMdPreview from '@kangc/v-md-editor/lib/preview';
import '@kangc/v-md-editor/lib/style/preview.css';
import '@kangc/v-md-editor/lib/theme/style/github.css';


VMdPreview.use(githubTheme, {
  Hljs: hljs,
});

const app=createApp(App)

app.use(router)

app.use(ElementPlus)
// app.use(Unicon)
app.use(VMdEditor)
app.use(VMdPreview)


app.mount('#app')

app.config.globalProperties.$filters = {
    ellipsis(value, len, maxChar=100){
        let counter=0
        let maxCounter = 0
        let result = ""
        for(let c of value){
            if(maxCounter>maxChar)break
            maxCounter+=1
            if(/[\s\t]/.test(c)) {counter++;result+=' '}
            if(counter>len) break
            result+=c
        }
        
        return result
    },
    timeFormatter(value){
        // input format: 2021-06-11T00:48:47.843901+08:00
        // output format: 2021-06-11 00:48:47
        return value.split(/[T\.]/).slice(0,2).join(' ')
    }
}

// 监听localstorage
const oSetItem = localStorage.setItem

localStorage.setItem = function(k, v){
    const setItemEvent = new Event("setItemEvent")
    setItemEvent[k] = v
    oSetItem.apply(this, arguments)
    window.dispatchEvent(setItemEvent)
}